#nullable enable

using System.Collections.Generic;

namespace PHMEE.EnergyEfficiency;

/// <summary>
/// 燃料
/// </summary>
public enum FuelType
{
    /// <summary>
    /// 重柴油（柴油）
    /// </summary>
    MDO = 0,

    /// <summary>
    /// 轻柴油（汽油）
    /// </summary>
    MGO = 1,

    /// <summary>
    /// 轻燃油
    /// </summary>
    LFO = 2,

    /// <summary>
    /// 重燃油
    /// </summary>
    HFO = 5,

    /// <summary>
    /// 液化石油气-丙烷 LPG Propane
    /// </summary>
    LPGP = 8,

    /// <summary>
    /// 液化石油气-丁烷 LPG Butane
    /// </summary>
    LPGB = 9,

    /// <summary>
    /// 液化天然气
    /// </summary>
    LNG = 10,

    /// <summary>
    /// 甲醇
    /// </summary>
    Methanol = 11,

    /// <summary>
    /// 乙醇
    /// </summary>
    Ethanol = 12,

    // 完善后的新增油品
    LSHFO = 13,
    LSLFO = 14,
    LSMGO = 15,
    ULSFO2020 = 16,
    ULSLFO2020 = 17,
    ULSMDO2020 = 18,
    ULSMGO2020 = 19,
    VLSFO2020 = 20,
    VLSLFO2020 = 21,

    // UnKnown 仅用于判断，不应保存到库中
    UnKnown = 99
}

public static class FuelTypeHelper
{
    /// <summary>
    /// N2O Emission Factor TBM FuelTypes
    /// </summary>
    public static readonly List<FuelType> N2O_EF_TBM_FuelTypes =
    [
        FuelType.LPGP,
        FuelType.LPGB,
        FuelType.Methanol,
        FuelType.Ethanol,
        FuelType.LSLFO,
        FuelType.LSMGO,
        FuelType.ULSLFO2020,
        FuelType.ULSMDO2020,
        FuelType.ULSMGO2020,
        FuelType.VLSLFO2020,
    ];
    
    /// <summary>
    /// CH4 Emission Factor TBM FuelTypes
    /// </summary>
    public static readonly List<FuelType> CH4_EF_TBM_FuelTypes =
    [
        FuelType.LPGP,
        FuelType.LPGB,
        FuelType.Methanol,
        FuelType.Ethanol,
        FuelType.LSLFO,
        FuelType.LSMGO,
        FuelType.ULSLFO2020,
        FuelType.ULSMDO2020,
        FuelType.ULSMGO2020,
        FuelType.VLSLFO2020,
    ];

    /// <summary>
    /// 根据油品，获取 IMODCS 报表中的油品列表。
    /// 因为在 IMO DCS 报表中，LSHFO 等油品也要算给 HFO，其它油品也是类似。
    /// </summary>
    /// <param name="fuelType"></param>
    /// <returns></returns>
    public static List<FuelType> GetFuelTypesForIMODCSReport(FuelType fuelType)
    {
        if (fuelType is FuelType.HFO)
        {
            return
            [
                FuelType.HFO,
                FuelType.LSHFO,
                FuelType.ULSFO2020,
                FuelType.VLSFO2020
            ];
        }
        
        if (fuelType is FuelType.LFO)
        {
            return
            [
                FuelType.LFO,
                FuelType.LSLFO,
                FuelType.ULSLFO2020,
                FuelType.VLSLFO2020
            ];
        }
        
        if (fuelType is FuelType.MDO or FuelType.MGO)
        {
            return
            [
                FuelType.MDO,
                FuelType.MGO,
                FuelType.LSMGO,
                FuelType.ULSMGO2020,
                FuelType.ULSMDO2020
            ];
        }

        // 仅 HFO、LFO 和 MDO/MGO 对应多种油品，其它的油品直接返回自身
        return [fuelType];
    }
}